package com.example.jackson.csv;

import com.fasterxml.jackson.databind.SequenceWriter;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Boot {

    public static void main(String[] args) throws Exception {

        CsvMapper mapper = CsvMapper.csvBuilder().build();
        CsvSchema schema = mapper.schemaFor(PageRow.class).withHeader();

        List<PageRow> rows = new ArrayList<>();
        rows.add(PageRow.test("亞洲有碼原創區", "【HD/2.07GB】ATID-590 「绝对不能原谅不伦」我曾这样想，但却陷入了儿子所就读的足球教室教练的不伦关系。 三宫椿", "https://cl.9202z.xyz/htm_data/2403/15/6210532.html", "六岁抬头", "https://cl.9202z.xyz/thread0806.php?fid=15&search=554094", "03-02 05:12\n" + "糖葱薄饼"));
        rows.add(PageRow.test("亞洲有碼原創區", "[HD/5.3G] ABF-083 絶対忠実秘書 鈴村あいり", "https://cl.9202z.xyz/htm_data/2402/15/6207809.html", "wwg101", "https://cl.9202z.xyz/thread0806.php?fid=15&search=207930", "02-29 10:21\n" + "明日见未来"));
        rows.add(PageRow.test("亞洲有碼原創區", "【HD/2.46GB】MIDV-639 在同窗会上被背叛却还是享受了许多高潮... 石川澪", "https://cl.9202z.xyz/htm_data/2403/15/6210694.html", "六岁抬头", "https://cl.9202z.xyz/thread0806.php?fid=15&search=554094", "-"));
        rows.add(PageRow.test("亞洲有碼原創區", "[HD/3.6G] DLDSS-310 隣に住む童貞を誘惑し、絶倫チ◯ポを騎乗位でヌキまくる欲求不満妻 小野夕子", "https://cl.9202z.xyz/htm_data/2402/15/6207477.html", "wwg101", "https://cl.9202z.xyz/thread0806.php?fid=15&search=207930", "-"));

        File file = new File("C:\\Users\\fanhang\\git\\java-snippets\\jackson-csv\\src\\resources\\abc.csv");
        try (SequenceWriter sequenceWriter = mapper.writerFor(PageRow.class).with(schema).writeValues(file)) {
            sequenceWriter.writeAll(rows);
        }
    }

}
